package com.bm.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bm.common.util.Rutils;
import com.bm.common.vo.R;
import com.bm.server.dao.MyfriendDao;
import com.bm.server.entity.Myfriend;
import com.bm.server.service.intf.MyfriendService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * .=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-.
 * |                     ______                     |
 * |                  .-"      "-.                  |
 * |                 /            \                 |
 * |     _          |              |          _     |
 * |    ( \         |,  .-.  .-.  ,|         / )    |
 * |     > "=._     | )(__/  \__)( |     _.=" <     |
 * |    (_/"=._"=._ |/     /\     \| _.="_.="\_)    |
 * |           "=._"(_     ^^     _)"_.="           |
 * |               "=\__|IIIIII|__/="               |
 * |              _.="| \IIIIII/ |"=._              |
 * |    _     _.="_.="\          /"=._"=._     _    |
 * |   ( \_.="_.="     `--------`     "=._"=._/ )   |
 * |    > _.="                            "=._ <    |
 * |   (_/                                    \_)   |
 * |                                                |
 * '-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-='
 * -----------------代码的搬运工-----------------
 *
 * @Date: 2022/07/20/20:16
 */
@Service
public class MyfriendServiceImpl implements MyfriendService {
    @Resource
    private MyfriendDao dao;
    @Override
    public R save(int uid,String friendid) {
        if(friendid!=null || uid >0){
            Myfriend myfriend = new Myfriend();
            myfriend.setFriendid(friendid);
            myfriend.setUid(uid);
            dao.insert(myfriend);
            return Rutils.ok("添加成功");
        }
        return Rutils.fail("添加失败");
    }

    @Override
    public R isfriend(int uid, String friendid) {
       if(friendid!=null || uid >0){
           QueryWrapper<Myfriend> queryWrapper = new QueryWrapper<>();
           queryWrapper.eq("uid",uid);
           queryWrapper.eq("friendid",friendid);
           Myfriend myfriend = dao.selectOne(queryWrapper);
           if(myfriend!=null){
               return Rutils.ok("已经是好友了，请勿重复添加");
           }
       }
        return Rutils.fail("不是好友可以添加");
    }

    @Override
    public R selectmyfriends(int uid) {
        if(uid>0){
            return Rutils.ok(dao.selectmyfriend(uid));
        }
        return Rutils.fail();
    }

    @Override
    public R delete(int uid, String friendid) {
        if(friendid!=null || uid >0){
            QueryWrapper<Myfriend> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("uid",uid);
            queryWrapper.eq("friendid",friendid);
            if(dao.delete(queryWrapper)>0){
                return Rutils.ok("好友删除成功");
            }
        }
        return Rutils.fail("删除失败请重新删除");
    }
}
